<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>项目任务列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/font.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/xadmin.css') }}">
    <script src="{{ url_for('static', filename='lib/layui/layui.js') }}" charset="utf-8"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/xadmin.js') }}"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">

                <div class="layui-card-header">

                    <button class="layui-btn" onclick="xadmin.open('添加项目','{{ url_for('admin.items_add') }}',600,400)">
                        <i class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>序列</th>
                            <th>ID</th>
                            <th>项目名称</th>
                            <th>创建用户</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for i in datas.data_list %}
                            <tr>

                                <td>{{ loop.index }}</td>
                                <td>{{ i.id }}</td>
                                <td>{{ i.project }}</td>
                                <td>{{ i.user }}</td>
                                <td>{{ i.create_date.strftime("%Y-%m-%d %H:%M:%S") }}</td>

                                <td class="td-manage">
                                    <a title="删除" onclick="items_del(this,'{{ i.project }}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                    </a>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                            <div class="layui-page">

                                <ul class="pagination">
                                    {% if datas.show_status == 1 %}
                                        <li><a href="{{ url_for('admin.items') }}?p=1">首页</a></li>
                                        <li><a href="{{ url_for('admin.items') }}?p={{ datas.p - 1 }}">上一页</a></li>
                                    {% endif %}
                                    {% for li in datas.page_list %}
                                        {% if li == datas.p %}
                                            <li class="active"><span>{{ li }}</span></li>
                                        {% else %}
                                            <li><a href="{{ url_for('admin.items') }}?p={{ li }}">{{ li }}</a></li>
                                        {% endif %}
                                    {% endfor %}
                                    {% if datas.p < datas.page_total %}
                                        <li class=''><a href="{{ url_for('admin.items') }}?p={{ datas.p + 1 }}">下一页</a>
                                        </li>
                                        <li class=''><a
                                                href="{{ url_for('admin.items') }}?p={{ datas.page_total }}">尾页</a>
                                        </li>
                                    {% endif %}
                                </ul>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function (data) {

            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


    });


    /*任务删除*/
    function items_del(obj, name) {
        layer.confirm('确认要删除吗？',
            function (index) {

                //CSRF的固定写法
                var csrf_token = "{{ csrf_token() }}";

                $.ajaxSetup({
                    beforeSend: function (xhr, settings) {
                        if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                            xhr.setRequestHeader("X-CSRFToken", csrf_token);
                        }
                    }
                });

                var _data = {
                    "project": name,
                    'action': "delete",
                };

                $.ajax({
                    type: 'POST',
                    data: _data,
                    url: "{{ url_for('admin.items_controllers') }}",
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 200) {
                            layer.msg('已删除!', {
                                icon: 1,
                                time: 1000,
                            }, function () {
                                window.location.reload();
                            });

                        } else {
                            alert(data.msg, 0);
                        }
                    }
                });
            });
    }


</script>
</html>